const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {

  // 查询聊天记录
  return await db.collection('chatList')
  .where({
    $or: [
      { sendId: event.sendId, getId: event.getId },
      { sendId: event.getId, getId: event.sendId } // 确保两个方向的聊天记录都能查询到
    ]
  })
  .orderBy('timestamp', 'desc') // 按照时间戳降序排列（最新在前
  .get();
}
